﻿// Copyright (c) SimpleIdServer. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using Fido2NetLib.Objects;

namespace SimpleIdServer.IdServer.Webauthn.Models
{
    public class StoredFidoCredential
    {
        /// <summary>
        /// The type of the public key credential source.
        /// </summary>
        public PublicKeyCredentialType Type { get; set; } = PublicKeyCredentialType.PublicKey;

        /// <summary>
        /// The Credential ID of the public key credential source.
        /// </summary>
        public byte[] Id { get; set; }

        /// <summary>
        /// The credential public key of the public key credential source.
        /// </summary>
        public byte[] PublicKey { get; set; }

        /// <summary>
        /// The latest value of the signature counter in the authenticator data from any ceremony using the public key credential source.
        /// </summary>
        public uint SignCount { get; set; }

        /// <summary>
        /// The value returned from getTransports() when the public key credential source was registered.
        /// </summary>
        public AuthenticatorTransport[] Transports { get; set; }

        /// <summary>
        /// The value of the BE flag when the public key credential source was created.
        /// </summary>
        public bool BE { get; set; }

        /// <summary>
        /// The latest value of the BS flag in the authenticator data from any ceremony using the public key credential source.
        /// </summary>
        public bool BS { get; set; }

        /// <summary>
        /// The value of the attestationObject attribute when the public key credential source was registered. 
        /// Storing this enables the Relying Party to reference the credential's attestation statement at a later time.
        /// </summary>
        public byte[] AttestationObject { get; set; }

        /// <summary>
        /// The value of the clientDataJSON attribute when the public key credential source was registered. 
        /// Storing this in combination with the above attestationObject item enables the Relying Party to re-verify the attestation signature at a later time.
        /// </summary>
        public byte[] AttestationClientDataJSON { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public List<byte[]> DevicePublicKeys { get; set; }

        public byte[] UserId { get; set; }

        public PublicKeyCredentialDescriptor Descriptor { get; set; }

        public byte[] UserHandle { get; set; }

        public uint SignatureCounter => SignCount;

        public string CredType { get; set; }

        public DateTime RegDate { get; set; }

        public Guid AaGuid { get; set; }
    }
}
